<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>添加用户名</title>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="__PUBLIC__/css/font.css">
    <link rel="stylesheet" href="__PUBLIC__/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__PUBLIC__/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style type="text/css">
      .displaynone{
        display: none;
      }
    </style>
  </head>
  <body>
    <div class="x-nav">
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
      <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <button  class="layui-btn" style="margin-bottom:20px;" onclick="x_admin_show('添加产品标题','{:U('add_sort_page')}',350,230)">
          添加产品标题
        </button>
        <form class="layui-form">
          <div class="layui-form-item">
            <label class="layui-form-label">
                  产品名称：
            </label>
            <div class="layui-input-inline">
              <input type="text" id="product" name="product" required="" lay-verify="product"
            autocomplete="off" class="layui-input" value="{$p['product']}">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">
                  产品内容：
            </label>
            <div class="layui-input-inline">
             <textarea name="content" id="ue">{$p['content']}</textarea>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">
                  产品类别：
            </label>
            <div class="layui-input-inline">
              <select name="parentid" lay-verify="" lay-filter="a" id="parentid">
                <option value="0">请选择产品类别</option>
                <foreach name="sort" item="y">
                  <option <if condition="$y['id'] eq $p['parentid']">selected</if> value="{$y['id']}">{$y['sort']}</option>
                </foreach>
              </select>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">
                  备注：
            </label>
            <div class="layui-input-inline">
              <textarea name="beizhu" id="beizhu" lay-verify="beizhu"
            autocomplete="off" class="layui-input" style="height:100px;width:400px;">{$p['beizhu']}</textarea>
            <input type="hidden" name="id" value="{$id1}">
            </div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label">
                  选择图片：
              </label>
              <div class="layui-input-inline">
                <img id="img" src="__ROOT__/{$p['image']}" style="cursor:pointer;" width="130" height="130" border="0" onclick="if($(this).attr('src') == '__PUBLIC__/weizhi.png'){x_admin_show('上传图片','{:U('Common/add_image')}',350,180)}else{layer.msg('请先取消照片')}"/>
                <input type="hidden" name="image" id="image" value="{$p['image']}">
                <span style="color:red;cursor:pointer;" onclick="del_image()">取消图片</span>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                  提交
              </button>
          </div>
      </form>
    </div>
    <script type="text/javascript">
      function del_image(){
        var path = $("#image").val();
        if(path == ''){
          layer.msg('未选择图片');
          return false;
        }
        $.ajax({
          url:"{:U('Common/del_image')}",
          type:"post",
          data:{path:path},
          success:function(e){
          if(e.status == 1){
            $('#img').attr('src','__PUBLIC__/weizhi.png');
            $('#image').val('');
            layer.msg(e.info);
          }else{
            layer.msg(e.info);
          }
        }
        })
        return false;
      }
    </script>
    <script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.min.js"></script>
    <script type="text/javascript">
        UE.getEditor('ue',{
          initialFrameWidth:800,
          initialFrameHeight:200
        })
      </script>
    <script>
        layui.use(['form','layer'], function(){
          $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;

          //监听提交
          form.on('submit(add)', function(data){
            if($('#product').val() == ''){
              layer.msg('请填写产品名称!!');
              return false;
            }
            if($('#parentid').val() == 0){
              layer.msg('请选择产品类别!!');
              return false;
            }
            if($('#beizhu').val() == ''){
              layer.msg('请填写备注!!');
              return false;
            }
            if($('#image').val() == ''){
               layer.msg('请添加图片!!');
              return false;
            }
            $.ajax({
                url:'{:U("Product/save_product")}',
                data:$("form").serialize(),
                type:'post',
                success:function(e){
                  if(e.status == 1){
                    layer.alert("编辑成功", {icon: 6},function () {
                      parent.location.reload();
                    });
                  }else{
                    layer.msg('数据未编辑成功');
                  }
                },
                error:function(e){
                    console.log(e);
                }
            })
            return false;
          });
        });
    </script>
    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();</script>
  </body>

</html>